package com.platform.api;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.platform.annotation.IgnoreAuth;
import com.platform.entity.FarmTypeEntity;
import com.platform.service.FarmTypeService;
import com.platform.util.ApiBaseAction;
import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * 农机类型表一级Controller
 *
 * @author lipengjun
 * @email 939961241@qq.com
 * @date 2020-02-10 21:58:37
 */
@Api(tags = "农机手册目录项")
@RestController
@RequestMapping("/api/farmtype")
public class FarmTypeController extends ApiBaseAction{
    @Autowired
    private FarmTypeService farmTypeService;
    
    /**
     * 查看所有列表接口
     */
    @ApiOperation(value = "查询农机手册全部信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "农机手册id", paramType = "path", required = true)})
    @GetMapping(value = "queryAll")
    @IgnoreAuth
    //@RequestMapping("/queryAll")
    public Object queryAll(@RequestParam Map<String, Object> params) {

        List<FarmTypeEntity> list = farmTypeService.queryList(params);

        return toResponsSuccess(list);
    }
    

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("farmtype:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<FarmTypeEntity> farmTypeList = farmTypeService.queryList(query);
        int total = farmTypeService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(farmTypeList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @ApiOperation(value = "查询农机手册信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "农机手册id", paramType = "path", required = true)})
    @GetMapping(value = "info")
    //@RequestMapping("/info/{id}")
    //@RequiresPermissions("farmtype:info")
    public R info(@PathVariable("id") Integer id) {
        FarmTypeEntity farmType = farmTypeService.queryObject(id);
        return R.ok().put("farmType", farmType);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("farmtype:save")
    public R save(@RequestBody FarmTypeEntity farmType) {
        farmTypeService.save(farmType);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("farmtype:update")
    public R update(@RequestBody FarmTypeEntity farmType) {
        farmTypeService.update(farmType);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("farmtype:delete")
    public R delete(@RequestBody Integer[] ids) {
        farmTypeService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    //@ApiImplicitParams({@ApiImplicitParam(name = "id", value = "农机手册id", paramType = "path", required = true)})
    //@GetMapping(value = "queryAll")
    //@IgnoreAuth
    @RequestMapping("/queryall")
    public R queryall(@RequestParam Map<String, Object> params) {

        List<FarmTypeEntity> list = farmTypeService.queryList(params);

        return R.ok().put("list", list);
    }
}
